<template>
  <el-row class="tac">
    <el-col :span="24">
      <h1>体检预约</h1>
      <el-menu :default-active="routerPath" class="el-menu-vertical-demo" background-color="#273146" text-color="#fff"
        active-text-color="#ffd04b" active-background-color="#ffd04b" router @open="handleOpen" @close="handleClose">

        <!-- <div v-for="item in nav" :key="item.id" >
          <el-menu-item v-if="item.children.length == 0" :index="item.path" @click="breadid(item.id,0)">
            <i :class="item.icon"></i>
            <span>{{ item.name }}</span>
          </el-menu-item>

          <el-submenu :key="item.path" :index="item.path" v-else>
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{ item.name }}</span>
            </template>
            <el-menu-item-group v-for="itemson in item.children" :key="itemson.id">
              <el-menu-item :index="item.path+'/'+itemson.path" @click="breadid(item.id,itemson.id)">{{ itemson.name }}</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </div> -->
        <div v-for="item in nav" :key="item.id">
          <el-menu-item :index="'/'+item.path" @click="breadid(item.id, 0)" v-if="item.children.length == 0">
            <i :class="item.icon"></i>
            <span> {{ item.name }}</span>
          </el-menu-item>
          <el-submenu :key="item.path" :index="'/'+item.path" v-else>
            <template slot="title">
              <i :class="item.icon"></i>
              <span> {{ item.name }}</span>
            </template>
            <el-menu-item-group v-for="itemson in item.children" :key="itemson.id">
               <el-menu-item :index="'/'+item.path+'/'+itemson.path" @click="breadid(item.id,itemson.id)">{{ itemson.name }}</el-menu-item>
            </el-menu-item-group>
          </el-submenu>

        </div>
      </el-menu>
    </el-col>
  </el-row>
</template>

<script>
export default {
  data() {
    return {
      defaultName: "1",
      routerPath: this.$route.path,
      nav: []
    };
  },
  methods: {
    breadid(firstid, lastid) {
      this.$emit("breadid", firstid, lastid);
    },
    handleOpen(key, keyPath) {
      // console.log(this.routerPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    },
  },
  created() {
    this.$axios({
      url: '/menu/findAll',
      method: 'get',
    }).then(res => {
      this.$store.commit("addNav", res.data);
      this.nav = res.data
      // console.log(this.nav);
    })
  }
};
</script>

<style>
h1 {
  color: white;
  font-size: 1.6rem;
  text-align: center;
}

.item-a {
  font-size: 14px;
}
</style>